//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package templet;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class FileUtil {
    public FileUtil() {
    }
    
    public static String getContent(String fileName) {
        File file = new File(fileName);
        String result = "";
        
        try {
            InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "UTF-8");
            BufferedReader read = new BufferedReader(isr);
            
            for(String s = null; (s = read.readLine()) != null; result = result + s + "\n") {
            }
            
            read.close();
        } catch (Exception var6) {
            var6.printStackTrace();
        }
        
        return result;
    }
    
    public static void setContent(String filePath, String content) {
        try {
            File f = new File(filePath);
            if (f.exists()) {
                f.delete();
            }
            
            File pathf = f.getParentFile();
            if (!pathf.exists()) {
                pathf.mkdirs();
            }
            
            f.createNewFile();
            FileOutputStream fout = new FileOutputStream(f);
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fout, "UTF-8"));
            writer.write(content);
            writer.close();
            System.out.println("生成代码：" + filePath);
        } catch (Exception var6) {
            var6.printStackTrace();
        }
        
    }
    
    public static boolean isTemplatFile(String filename) {
        String extensionName = getExtensionName(filename);
        if (extensionName.equals("html")) {
            return true;
        } else if (extensionName.equals("java")) {
            return true;
        } else if (extensionName.equals("xml")) {
            return true;
        } else if (extensionName.equals("htm")) {
            return true;
        } else if (extensionName.equals("jsp")) {
            return true;
        } else if (extensionName.equals("project")) {
            return true;
        } else if (extensionName.equals("component")) {
            return true;
        } else {
            return extensionName.indexOf("(TFILE)") > 0;
        }
    }
    
    public static String getExtensionName(String filename) {
        if (filename != null && filename.length() > 0) {
            int dot = filename.lastIndexOf(46);
            if (dot > -1 && dot < filename.length() - 1) {
                return filename.substring(dot + 1);
            }
        }
        
        return filename;
    }
    
    public static void copyFile(String oldPath, String newPath) {
        try {
            int bytesum = 0;
            // int byteread = false;
            File oldfile = new File(oldPath);
            if (oldfile.exists()) {
                File newpath = new File(newPath);
                if (!newpath.getParentFile().exists()) {
                    newpath.getParentFile().mkdirs();
                }
                
                InputStream inStream = new FileInputStream(oldPath);
                FileOutputStream fs = new FileOutputStream(newPath);
                byte[] buffer = new byte[1444];
                
                int byteread;
                while((byteread = inStream.read(buffer)) != -1) {
                    bytesum += byteread;
                    fs.write(buffer, 0, byteread);
                }
                
                inStream.close();
            }
        } catch (Exception var9) {
            System.out.println("复制单个文件操作出错!原文件:" + oldPath + " 新文件：" + newPath);
        }
        
    }
}
